﻿using System;

namespace EmbeddedSharp.Core.Function.Maths {

    /// <summary>
    /// roundedPI=round(3.1415926, 2);
    /// echo(roundedPI);
    /// 
    /// The result is 
    /// 3.14
    /// </summary>
    public class RoundNode : FuncNode {

        public RoundNode()
            : base() {
            base.Value = "round";
        }

        public override object Evaluate() {
            if (this.Parameters.Count < 1)
            {
                throw new ArgumentException();
            }

            double result = Convert.ToDouble(
                Parameters[0].Evaluate());

            return System.Math.Round(result).ToString();
        }
    }
}
